GIT 分支新建与合并
1. 分支新建与合并
1.1. 分支的使用场景
1.开发某个程序。
2.实现新的需求,创建一个分支(function)。
3.在这个分支上展开工作。
6.紧急电话有个项目要特殊版本。
7.切换到你的线上分支。也是主分支(master)
8.创建新的分支,并在这个分支上修复BUG 。(BUG 分支)
9.测试后切换回主分支,合并这个修补分支,最后提交到主分支(master 分支)
10.切换最初的分支(function)继续工作。
1.2. 实际操作
- 创建分支
git co -b iss53
等于
git br isss53
git co iss53

- 进行工作。
$ vim index.html
$ git commit -a -m 'added a new footer [issue 53]'

- 突发事件:
- 切换为master 分支。
git co master
- 创建fixbug 分支。
git co -b hotfix
- 修改修复后切换到master 分支。
 - 来合并分支hotfix
$ git checkout master
git merge hotfix
- 发布新版本修复bug.
 - 删除紧急维护的分支。
git br -d hotfix
- 切回iss53 功能测试分支
 - 测试完成后 合并分支。
git merge iss53


注意此处做了一次三方合并
- 删除 功能添加分支
git br -d iss53
2. 分支冲突合并
- 如果对同一个文件修改了。则会合并冲突。
- 解决步骤:
$ git merge bugfix
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
aming@aming-PC MINGW64 /d/scripts/test (master|MERGING)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 5 commits.
(use "git push" to publish your local commits)
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
aming@aming-PC MINGW64 /d/scripts/test (master|MERGING)